home *** CD-ROM | disk | FTP | other *** search
- unit Gifimage;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls, CCGIF;
-
- type
- TGifImage = class(TImage)
- private
- { Private declarations }
- FTheFileName : String;
- TheGif : PGif;
- protected
- { Protected declarations }
- OldFileName : String;
- TheBitmap : TBitmap;
- valid_load : Boolean;
- public
- { Public declarations }
- constructor Create( AOwner : TComponent ); override;
- destructor Destroy; override;
- procedure Paint; override;
- procedure LoadGIFFile;
- published
- { Published declarations }
- property TheFileName : String read FTheFileName write FTheFileName;
- end;
-
- procedure Register;
-
- implementation
-
- constructor TGIFImage.Create( AOwner : TComponent );
- begin
- inherited Create( AOwner );
- TheBitmap := TBitmap.Create;
- end;
-
- destructor TGIFImage.Destroy;
- begin
- TheBitmap.Free;
- inherited Destroy;
- end;
-
- procedure TGIFImage.LoadGIFFile;
- var thebuffer : array[ 0..255] of char;
- TheGif : PGif;
- begin
- Valid_Load := false;
- if not FileExists( TheFileName ) then
- begin
- MessageDlg( TheFileName + ' cannot be found!',mterror,[mbOK],0);
- exit;
- end;
- Screen.Cursor := crHourGlass;
- StrPCopy( TheBuffer , TheFilename );
- TheGif := NEW( PGif , Init( theBuffer ));
- TheBitmap.Width := TheGif^.ImageDescriptor.ImageWidth;
- TheBitmap.Height := TheGif^.ImageDescriptor.ImageHeight;
- TheGif^.Decode( false , TheBitmap );
- Dispose( TheGif , Done );
- Screen.Cursor := crDefault;
- oldFileName := TheFileName;
- valid_load := true;
- end;
-
- procedure TGIFImage.Paint;
- begin
- if csDesigning in ComponentState then
- begin
- inherited Paint;
- exit;
- end;
- if TheFileName = '' then
- begin
- inherited Paint;
- exit;
- end;
- if oldfilename <> Thefilename then
- begin
- LoadGIFFile;
- if not Valid_load then
- begin
- Picture.Bitmap.Height := 0;
- Picture.Bitmap.Width := 0;
- inherited Paint;
- exit;
- end;
- Picture.Bitmap.Height := TheBitmap.Height;
- Picture.Bitmap.Width := TheBitmap.Width;
- Picture.Bitmap.Handle := TheBitmap.Handle;
- inherited Paint;
- exit;
- end;
- inherited Paint;
- end;
-
- procedure Register;
- begin
- RegisterComponents('Widgets', [TGifImage]);
- end;
-
- end.
-